import {defineStore} from "pinia";

interface AppState {
    /**
     * 系统名
     */
    systemName: string,
    /**
     * 系统版本
     */
    systemVersion: string,
    /**
     * 重载页面(控制页面的显示)
     */
    reloadFlag: boolean;
    /**
     * 侧边栏折叠状态
     */
    sideCollapse: boolean;
    /**
     * 是否暗黑模式
     */
    darkMode: boolean;
    /**
     * 上次操作时间
     */
    lastTime: number;
}

export const useAppStore = defineStore('app-store', {
    state: (): AppState => ({
        systemName: 'XXX管理系统',
        systemVersion: '0.0.1',
        reloadFlag: false,
        sideCollapse: false,
        darkMode: false,
        lastTime: 0
    }),
    actions: {
        /** 折叠/展开 侧边栏折叠状态 */
        toggleSideCollapse() {
            this.sideCollapse = !this.sideCollapse;
        },
        /** 切换主题 */
        toggleDarkMode() {
            this.darkMode = !this.darkMode;
            if (this.darkMode) {
                document.documentElement.setAttribute('theme-mode', 'dark');
            } else {
                document.documentElement.removeAttribute('theme-mode');
            }
        },
    }
})